import { unref, ref, watch, Ref } from "vue";
import { MayBeRef } from "@model/util";

/**
 * Set your browser title.
 */
export default function (title?: MayBeRef<string>): Ref<string> {
	const titleValue = ref(unref(title || document.title));
	watch(
		titleValue,
		value => {
			document.title = value;
		},
		{
			immediate: true,
		},
	);
	return titleValue;
}
